class Solution:
    def preimageSizeFZF(self, K: int) -> int:
        i = 0
        while (5 ** (i + 1) - 1) / 4 < K - 2:
            i += 1
        while i >= 1:
            if K % ((5 ** (i + 1) - 1) / 4) == (5 ** (i + 1) - 1) / 4 - 1:
                return 0
            else:
                K -= (K // ((5 ** (i + 1) - 1) / 4))
                i -= 1
        return 5


a = Solution()
print(a.preimageSizeFZF(0))
print(a.preimageSizeFZF(5))
